import { defineEventHandler, createError } from 'h3'
import { FileModel } from 'server/models/File'

export default defineEventHandler(async (event) => {
  try {
    // 获取文件统计信息
    const stats = await FileModel.getStats()

    return {
      success: true,
      data: stats
    }

  } catch (error: any) {
    console.error('获取文件统计信息错误:', error)
    
    if (error.statusCode) {
      throw error
    }

    throw createError({
      statusCode: 500,
      statusMessage: error.message || '服务器内部错误'
    })
  }
})